package com.wry.wry_test.algorithm;

/**
 * @Author: wangrongyi
 * @Date: 2024/11/13 9:44
 * @Description:
 */
public class Day08 {
    public static String solution(String s) {
        // write code here
        if (s == null || s.isEmpty()) {
            return "";
        }
        String res = "";
        String tail = "";
        if (s.contains(".")) {
            tail = s.substring(s.indexOf("."));
            s = s.substring(0, s.indexOf("."));
        }

        long num = Long.parseLong(s);
        if (num == 0) {
            return "0" + tail;
        }
        while (num > 0) {
            long temp = num % 1000;
            num = num / 1000;
            if (num > 0) {
                res = String.format(",%03d", temp) + res;
            }else {
                res = temp + res;
            }

        }
//        res = res.substring(0, res.length() - 1);

        System.out.println(res + tail);
        return res + tail;
    }

    public static void main(String[] args) {
        System.out.println(solution("1294512.12412").equals("1,294,512.12412"));
        System.out.println(solution("0000123456789.99").equals("123,456,789.99"));
        System.out.println(solution("987654321").equals("987,654,321"));
    }
}
